#ifndef SNCascadeBoost_h__
#define SNCascadeBoost_h__
//----------------------------------------------------------------
#include "SNFeatureEvaluator.h"
#include "SNCascadeBoostParams.h"
#include "opencv2\core\internal.hpp"
//----------------------------------------------------------------
#define SN_THRESHOLD_EPS (0.00001F)
//----------------------------------------------------------------
#define CV_CMP_FLT(i,j) (i < j)
static CV_IMPLEMENT_QSORT_EX(SNSortFlt, float, CV_CMP_FLT, const float*)
//----------------------------------------------------------------

class SNCascadeBoost : public CvBoost
{
public:
	SNCascadeBoost();
	~SNCascadeBoost();

	virtual bool Train(const SNFeatureEvaluator* feature_evaluator,
		int num_samples, int precalc_val_buf_size, int precalc_idx_buf_size,
		const SNCascadeBoostParams& _params = SNCascadeBoostParams());

	virtual float Predict(int sampleIdx, bool returnSum = false) const;

	float getThreshold() const { return threshold; }
	void write(cv::FileStorage &fs, const cv::Mat& featureMap) const;
	bool read(const cv::FileNode &node, const SNFeatureEvaluator* _featureEvaluator, const SNCascadeBoostParams& _params);
	void markUsedFeaturesInMap(cv::Mat& featureMap);
protected:
	virtual bool SetParams(const CvBoostParams& params);
	virtual void UpdateWeights(CvBoostTree* tree);
	virtual bool IsErrDesired();

	float threshold;
	float MinHitRate;
	float MaxFalseAlarm;
};
//----------------------------------------------------------------
#endif // SNCascadeBoost_h__

